package com.joysuch.wwyt.workflow.utils;

import com.mysema.commons.lang.Assert;
import org.springframework.context.ApplicationContext;

public class ApplicationContextHolder {

    private static ApplicationContext context;

    public static void setApplicationContext(ApplicationContext applicationContext) {
        context = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return context;
    }

    public static <T>  T getBean(Class<T> clazz) {
        checkApplication();
        return context.getBean(clazz);
    }

    private static void checkApplication() {
        Assert.notNull(context, "ApplicationContextHolder未初始化");
    }
}
